package hero_info

import (
	"go_server/game_server/protocol/pb"
	"go_server/zinx/ziface"
	"go_server/zinx/zlog"
)

func (s *Hero_info_service) S2C_GetHeros(conn ziface.IConnection, roleid int64) pb.ErrorCodeManager {
	hero := Hero_info_serviceObj.LoadByRoleId(roleid)
	msgS2C := s.on_S2C_GetHeros(hero)
	if msgS2C != nil {
		zlog.Debugf("ProtocolManager_GetHeros %v", msgS2C)
		defer func() {
			conn.SendBuffPBMsg(uint32(pb.ProtocolManager_GetHeros), msgS2C)
		}()
	}
	return pb.ErrorCodeManager_SUCCESS
}

func (s *Hero_info_service) on_S2C_GetHeros(hero *Cache_hero_info) *pb.GetHerosS2C {
	msgS2C := &pb.GetHerosS2C{}
	if hero != nil && hero.Heros != nil {
		for _, hv := range hero.Heros {
			msgS2C.Heros = append(msgS2C.Heros, hv.ToPB_HeroCardData())
		}
	}
	return msgS2C
}
